# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=uusi
pkgver=0.4.3.0
pkgrel=17
pkgdesc="Tweak .cabal files"
url="https://github.com/berberman/uusi"
license=("MIT")
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc')
checkdepends=('haskell-hunit')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('a7a7c7b352aba0edb33aa2c7663bfdc179ba5338281b72373670e57a1ed4c26ce1a6ae8c7f72e9841837bb43007b40715d70ee3408e4049fd47167b8151aeceb')

build() {
  cd $pkgname-$pkgver

  if (( CHECKFUNC )); then
    _opts=('--enable-tests')
  else
    _opts=('--disable-tests')
  fi

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie'

  runhaskell Setup build $MAKEFLAGS
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver

  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
